package com.zhongge.deque;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @ClassName TestDeque
 * @Description TODO 测试双端队列
 * @Author 笨忠
 * @Date 2025/8/30 10:05
 * @Version 1.0
 */
public class TestDeque {
    public static void main(String[] args) {
        //链式实现
        Deque<Integer> deque = new LinkedList<>();
        deque.offerFirst(10);//从头入队
        deque.offerFirst(20);
        System.out.println(deque.pollLast());//从尾出队
        System.out.println(deque.pollLast());

        //顺序实现
        Deque<Integer> deque1 = new ArrayDeque<>();
        deque1.offer(10);//入队
        deque1.offer(20);
        System.out.println(deque1.poll());//出队
        System.out.println(deque1.poll());


        //双端队列模拟实现栈
        Deque<String> stack = new LinkedList<>();
        //入栈
        stack.push("刘备");
        stack.push("关羽");
        stack.push("张飞");

        //出栈
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
    }
}
